package com.zzjson;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : com.zzjson</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年09月11日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class BlockingDemo {
	private ArrayBlockingQueue<String> arrayBlockingQueue = new ArrayBlockingQueue(10);

	public static void main(String[] args) throws InterruptedException {
		BlockingDemo blockingDemo = new BlockingDemo();
		blockingDemo.init();
		for (int i = 0; i < 1000; i++) {
			blockingDemo.addData(i + "");
		}
	}

	public void init() {
		new Thread(() -> {
			while (true) {
				try {
					String data = arrayBlockingQueue.take();
					System.out.println("reciive:" + data);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		}).start();
	}

	public void addData(String data) throws InterruptedException {
		System.out.println("send data i" + data);
		arrayBlockingQueue.add(data);
		Thread.sleep(1000);
	}
}